package com.codeZ.FactoryPattern.factoryMethod.controller;

import com.codeZ.FactoryPattern.entity.AwardInfo;
import com.codeZ.FactoryPattern.entity.ResponseResult;
import com.codeZ.FactoryPattern.factoryMethod.factory.IFreeGoodsFactory;
import com.codeZ.FactoryPattern.factoryMethod.factory.IFreeGoodsFactoryMap;
import com.codeZ.FactoryPattern.factoryMethod.product.IFreeGoods;

/**
 * 发送奖品客户端接口
 *
 * @author codeZhang
 * @Date 2024/8/1 14:55
 */
public class DeliverController {


    public ResponseResult sendFreeGoods(AwardInfo awardInfo) {
        // 奖品类型
        Integer awardTypes = awardInfo.getAwardTypes();
        // 奖品工厂
        IFreeGoodsFactory freeGoodsFactory = IFreeGoodsFactoryMap.getParserFactory(awardTypes);
        // 奖品工厂创建奖品
        if (freeGoodsFactory == null) {
            return new ResponseResult("404", "奖品类型有误!", null);
        }
        // 奖品
        IFreeGoods freeGoods = freeGoodsFactory.getInstance();
        // 发送奖品
        return freeGoods.sendFreeGoods(awardInfo);
    }

}
